package com.vrv.netmgr.database;

import java.sql.SQLException;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import com.vrv.netmgr.database.table.AlarmStatistics;
import com.vrv.netmgr.database.table.EquipmentChanged;
import com.vrv.netmgr.database.table.UpdateLog;

public class DatabaseHelper extends OrmLiteSqliteOpenHelper{

	private static final String DATABASE_NAME = "edpdm.db";
	private static final int DATABASE_VERSION = 1;

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase arg0, ConnectionSource arg1) {
		// TODO Auto-generated method stub
		try {
			TableUtils.createTable(connectionSource, UpdateLog.class);
			TableUtils.createTable(connectionSource, AlarmStatistics.class);
			TableUtils.createTable(connectionSource, EquipmentChanged.class);
			
		} catch (SQLException e) {
			Log.e(DatabaseHelper.class.getName(), "创建数据库失败", e);
			e.printStackTrace();
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, ConnectionSource arg1, int arg2,
			int arg3) {
		// TODO Auto-generated method stub
		try {
			TableUtils.dropTable(connectionSource, UpdateLog.class, true);
			TableUtils.dropTable(connectionSource, AlarmStatistics.class, true);
			TableUtils.dropTable(connectionSource, EquipmentChanged.class, true);
			
			onCreate(arg0, connectionSource);
		} catch (SQLException e) {
			Log.e(DatabaseHelper.class.getName(), "更新数据库失败", e);
			e.printStackTrace();
		}
	}
	
	@Override
	public void close() {
		super.close();
	}

}
